/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: Zhaoningbo
 * Date: 2011-7-21 下午05:08:47
 */
package action;

import java.io.Serializable;
import java.util.Map;

import dao.BookDao;

public class QueryAction implements Serializable {

    private static final long serialVersionUID = -8061757432366189244L;
    
    private String pattern;
    private Map<String, Integer> books;

    public String execute() throws Exception {

        try {
            
//            // 获取http请求中的参数pattern
//            HttpServletRequest request = (HttpServletRequest) ActionContext
//                    .getContext().get(
//                            org.apache.struts2.StrutsStatics.HTTP_REQUEST);
//            
//          String pattern = request.getParameter("pattern");
            BookDao bookDao = new BookDao();
            
            Map<String, Integer> books = bookDao.getBooks(this.pattern);
            //request.setAttribute("books", books);
            
            this.setBooks(books);
            
            return "result";
        } catch (Exception e) {
            return "error";
        }

    }

    public String getPattern() {
        return pattern;
    }

    public void setPattern(String pattern) {
        this.pattern = pattern;
    }

    public Map<String, Integer> getBooks() {
        return books;
    }

    public void setBooks(Map<String, Integer> books) {
        this.books = books;
    }
}
